package org.com.yz.dubbo.web.ctrl;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @ClassName weatherCtr
 * @Author wzc
 * @Date 2018/8/6 9:59
 **/
@RestController
public class WeatherCtr {


    /**
     * @Description: 网络请求接口
     * @author wzc
     * @date 2018/8/6 10:08
     */
    @RequestMapping("/api/weather.htm")
    public String weather() throws IOException {

        //拼地址
        String apiUrl = String.format("https://www.baidu.com");
        //开始请求
        URL url = new URL(apiUrl);
        URLConnection open = url.openConnection();
        InputStream input = open.getInputStream();
        String result = org.apache.commons.io.IOUtils.toString(input, "utf-8");
        //输出
        System.out.println(result);
        return result;
    }

}
